home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / TinyGL / ami / content / ad709 / tinygl / src / select.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-15  |  1.7 KB  |  81 lines

  1. /*$T select.c GC 1.137 08/09/02 17:47:18 */
  2.  
  3. /*$6
  4.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6.  */
  7.  
  8. #include "zgl.h"
  9.  
  10. /* */
  11. void glopInitNames(GLContext *c, GLParam *p) {
  12.     if(c->render_mode == GL_SELECT) {
  13.         c->name_stack_size = 0;
  14.         c->select_hit = NULL;
  15.     }
  16. }
  17.  
  18. /* */
  19. void glopPushName(GLContext *c, GLParam *p) {
  20.     if(c->render_mode == GL_SELECT) {
  21.         assert(c->name_stack_size < MAX_NAME_STACK_DEPTH);
  22.         c->name_stack[c->name_stack_size++] = p[1].i;
  23.         c->select_hit = NULL;
  24.     }
  25. }
  26.  
  27. /* */
  28. void glopPopName(GLContext *c, GLParam *p) {
  29.     if(c->render_mode == GL_SELECT) {
  30.         assert(c->name_stack_size > 0);
  31.         c->name_stack_size--;
  32.         c->select_hit = NULL;
  33.     }
  34. }
  35.  
  36. /* */
  37. void glopLoadName(GLContext *c, GLParam *p) {
  38.     if(c->render_mode == GL_SELECT) {
  39.         assert(c->name_stack_size > 0);
  40.         c->name_stack[c->name_stack_size - 1] = p[1].i;
  41.         c->select_hit = NULL;
  42.     }
  43. }
  44.  
  45. /* */
  46. void gl_add_select(GLContext *c, unsigned int zmin, unsigned int zmax) {
  47.     unsigned int    *ptr;
  48.     int                n, i;
  49.  
  50.     if(!c->select_overflow) {
  51.         if(c->select_hit == NULL) {
  52.             n = c->name_stack_size;
  53.             if((c->select_ptr - c->select_buffer + 3 + n) > c->select_size) {
  54.                 c->select_overflow = 1;
  55.             }
  56.             else {
  57.                 ptr = c->select_ptr;
  58.                 c->select_hit = ptr;
  59.                 *ptr++ = c->name_stack_size;
  60.                 *ptr++ = zmin;
  61.                 *ptr++ = zmax;
  62.                 for(i = 0; i < n; i++) {
  63.                     *ptr++ = c->name_stack[i];
  64.                 }
  65.  
  66.                 c->select_ptr = ptr;
  67.                 c->select_hits++;
  68.             }
  69.         }
  70.         else {
  71.             if(zmin < c->select_hit[1]) {
  72.                 c->select_hit[1] = zmin;
  73.             }
  74.  
  75.             if(zmax > c->select_hit[2]) {
  76.                 c->select_hit[2] = zmax;
  77.             }
  78.         }
  79.     }
  80. }
  81.